//
//  HJOrderDetailViewController.m
//  YaDiuDiu
//
//  Created by 胡光健 on 2017/10/29.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "HJOrderDetailViewController.h"
#import "StarView.h"
#import "HJGetOnModel.h"


@interface HJOrderDetailViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *bgScroll;
@property (weak, nonatomic) IBOutlet UILabel *orderNo;
@property (weak, nonatomic) IBOutlet UILabel *orderTiem;
@property (weak, nonatomic) IBOutlet UILabel *carname;
@property (weak, nonatomic) IBOutlet UILabel *carType;
@property (weak, nonatomic) IBOutlet UILabel *displacement;
@property (weak, nonatomic) IBOutlet UILabel *getOn;
@property (weak, nonatomic) IBOutlet UILabel *getOnAddress;
@property (weak, nonatomic) IBOutlet UILabel *carPhone;
@property (weak, nonatomic) IBOutlet UIImageView *invoice;
@property (weak, nonatomic) IBOutlet UIImageView *qualified;

@property (weak, nonatomic) IBOutlet UIImageView *card;
@property (weak, nonatomic) IBOutlet UIImageView *carFane;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btmH;

@property (weak, nonatomic) IBOutlet UILabel *comment;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIView *starView;
@property(nonatomic,strong)NSMutableDictionary * dic;
@property (weak, nonatomic) IBOutlet UIView *hideView;

@property (weak, nonatomic) IBOutlet UIButton *btn;
@property(nonatomic,strong)StarView *star;

@property(nonatomic,strong)HJResultModel * model;
@end

@implementation HJOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showNav:@"订单详情"];
    self.dic =[NSMutableDictionary dictionary];
    self.bgScroll.contentSize= CGSizeMake(ScreenWidth, 667);
    [self load];
}

-(void)load {
    NSString * url = [NSString stringWithFormat:@"%@%@",urlHead,@"/App/Ordermanage/ontheblesdetails"];
    [TZHttpTool post:url params:@{@"userid":[user objectForKey:@"userid"],@"merchantid":self.merchantid,@"id":self.id_shop} success:^(NSDictionary *result) {
        self.model =[[HJResultModel alloc]init];
        self.model = [HJResultModel mj_objectWithKeyValues:result[@"result"]];
        dispatch_async(dispatch_get_main_queue(), ^{
            
            self.orderNo.text =self.model.details.ordernumber;
            self.orderTiem.text = [TZHttpTool getNewDate:self.model.details.addtime];
            self.carname.text = self.model.details.brand;
            self.carType.text = self.model.details.models;
            self.displacement.text =self.model.details.displacement;
            self.getOn.text = self.model.details.ordermoney;
            self.getOnAddress.text = self.model.details.userarea;
            self.carPhone.text = self.model.details.ownerphone;
            [self.invoice sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],self.model.details.invoice]] placeholderImage:[UIImage imageNamed:@"TIM截图20170819150938"]];
            [self.qualified sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],self.model.details.certificate]] placeholderImage:[UIImage imageNamed:@"TIM截图20170819150938"]];
            [self.card sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],self.model.details.idcardone]] placeholderImage:[UIImage imageNamed:@"TIM截图20170819150938"]];
            [self.carFane sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],self.model.details.idcardtwo]] placeholderImage:[UIImage imageNamed:@"TIM截图20170819150938"]];
            
            if (self.type==2) {
                self.btmH.constant = 120.0;
                self.btn.hidden = NO;
                self.comment.hidden = NO;
                self.bgView.hidden= NO;
                self.star = [[StarView alloc]init];
                self.star.showStar = [self.model.comment.star integerValue]* 20;
                [self.starView addSubview:self.star];
                [self.star makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.equalTo(13);
                    make.top.equalTo(self.starView.top);
                    make.width.equalTo(80);
                    make.height.equalTo(16);
                }];
                if (self.model.comment.comment.length>0) {
                    self.comment.text= self.model.comment.comment;
                }else {
                    self.comment.text = @"暂无用户评价";
                }
            }else {
                self.btmH.constant = 0.01;
                self.btn.hidden = YES;
                self.comment.hidden = YES;
                self.bgView.hidden =YES;
            }
        });
    } failure:^(NSString *msg) {
        [LICGToast showWithText:msg];
    }];
}
- (IBAction)tellPhone:(UIButton *)sender {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.model.details.ownerphone]]];
}

@end
